<?php
$sanitize_all_escapes = true;
$fake_register_globals = false;
if (!isset($_REQUEST['medico'])) 
    session_start();

$landingpage = "index.php?site=" . $_SESSION['site_id'];
if (isset($_SESSION['pid']) && isset($_SESSION['patient_portal_onsite'])) {
    $pid = $_SESSION['pid'];
} else {
    session_destroy();
    header('Location: ' . $landingpage . '&w');
    exit;
}
$ignoreAuth = true;
require_once('../interface/globals.php');

// Session pid must be right or bad things can happen when demographics are saved!
//
include_once("$srcdir/pid.inc");

setpid($pid);
include_once("$srcdir/patient.inc");

$result = getPatientData($pid, "*, DATE_FORMAT(DOB,'%Y-%m-%d') as DOB_YMD");
?>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
        <title></title>
        <script type="text/javascript" src="<?php echo $web_root; ?>/library/dialog.js"></script>
        <script type="text/javascript" src="<?php echo $web_root; ?>/library/js/jquery-1.10.0.min.js"></script>
        <script type="text/javascript" src="<?php echo $web_root; ?>/library/js/jquery-migrate-1.2.1.min.js"></script>
        <script type="text/javascript" src="<?php echo $web_root; ?>/library/js/jquery.tools.min.js"></script>
        <script type="text/javascript" src="<?php echo $web_root; ?>/library/js/common.js"></script>
        <script type="text/javascript" src="<?php echo $web_root; ?>/patients/js/ajtooltip.js"></script>

        <script type="text/javascript" src="js/jquery.ui.core.js"></script>
        <script type="text/javascript" src="js/jquery.ui.widget.js"></script>
        <script type="text/javascript" src="js/jquery.ui.datepicker.js"></script>
        <script type="text/javascript" src="js/jquery.mask.min.js"></script>
        <!-- end -->

        <link rel="stylesheet" href="css/base.css" type="text/css"/>
        <link rel="stylesheet" href="css/nightingale.css" type="text/css"/>
        <link rel="stylesheet" href="css/datepickerAppointment.css" type="text/css"/>
        <link rel="stylesheet" href="<?php echo $GLOBALS['webroot'] ?>/library/js/redmond/jquery-ui-1.10.3.custom.min.css" type="text/css"/>
    </head>
    <body>
        <div id="fade" class="black_overlay"></div>

        <form id="contactForm" action="<?php echo $appointments; ?>" method="post">
            <input type='hidden' name='db_id' value="<?php echo $result['id'] ?>" />
            <h2 class="title">Solicitar una cita</h2>
            <div style="float: left; width: 48%; margin-left: 0px;">
                <p>Su nombre (requerido)<br>
                    <span>
                        <input type="text" placeholder="Por favor ingrese su nombre" required="required" size="40" 
                               value="<?php echo htmlspecialchars($result['fname'] . " " . $result['lname'], ENT_NOQUOTES); ?>" name="your-name" id="your-name">
                    </span> 
                </p>
                <p>Su correo electr&oacute;nico (requerido)<br>
                    <span>
                        <input type="email" placeholder="Por favor ingrese su correo electr&oacute;nico" required="required" size="40" 
                               value="<?php echo $result['email']; ?>" name="your-email" id="your-email">
                    </span>
                </p>
                <p>Tipo de paciente<bRr>
                    <span>
                        <select name="patient_type">
                            <option value="">---</option><option value="Paciente Nuevo">Soy un nuevo paciente</option>
                            <option value="Paciente Viejo">Soy un viejo paciente</option>
                        </select>
                    </span>
                    </p>
                    <p>&iquest;Que cl&iacute;nica desear&iacute;a visitar? (requerido)<br>
                        <span>
                            <select name="clinic" id="clinic" required="required" style="width: 246px;">
                                <option value="">---</option>
                                <option value="San Jose Centro">San Jos&eacute; Centro</option>
                                <option value="Sabana">Sabana Norte</option>
                                <option value="Cartago">Cartago</option>
                            </select>
                        </span>
                    </p>
                    <p>&iquest;Tiene un medico de preferencia?<br>
                        <span>
                            <select name="preferreddentist">
                                <option value="">---</option>
                                <option value="Si">S&iacute;</option>
                                <option value="No">No</option>
                            </select>
                        </span>
                    </p>
                    <p>&iquest;Nombre del medico de preferencia?<br>
                        <span>
                            <input type="text" size="40" value="" name="dentist_name">
                        </span>
                    </p>		
            </div>
            <div style="float: right; width: 45%; padding-right: 2em;">	
                <p>Fecha preferida para cita (requerido)<br>
                    <span>
                        <input class="my_datepicker" type="text" required="required" placeholder="dd/mm/aaaa" style="width: 194px;" size="40" value="" name="appointmentdate" id="appointmentdate"> </span>
                </p>
                <p>Hora preferida para cita (requerido)<br>
                    <span>
                        <select name="appointmenttime" id="appointmenttime" required="required" style="width: 189px;">
                            <option value="">---</option>
                            <option value="9:00 am">9:00 am</option>
                            <option value="10:00 am">10:00 am</option>
                            <option value="11:00 am">11:00 am</option>
                            <option value="12:00 nn">12:00 nn</option>
                            <option value="1:00 pm">1:00 pm</option>
                            <option value="2:00 pm">2:00 pm</option>
                            <option value="3:00 pm">3:00 pm</option>
                            <option value="4:00 pm">4:00 pm</option>
                            <option value="5:00 pm">5:00 pm</option>
                            <option value="6:00 pm">6:00 pm</option>
                        </select>
                    </span>
                </p>
                <p>N&uacute;mero de tel&eacute;fono (requerido)<br>
                    <span>
                        <input type="text" aria-required="true" required="required" placeholder="Por favor ingrese su tel&eacute;fono" size="40" 
                               value="<?php echo $result['phone_cell']?>" name="cellphone" id="cellphone"></span></p>
                <p>Su Mensaje<br>
                    <span><textarea class="wpcf7-form-control wpcf7-textarea" rows="5" cols="40" name="your-message"></textarea></span> </p>
                <p style="margin-bottom: 0px;">
                    <span style="float: left;">
                        <input type="checkbox" name="agreement" value="1" required="required" checked="checked" style="width: 15px;">
                    </span>
                    <span style="margin-left: 6px;"> Estoy de acuerdo que mi solicitud de cita esta sujeta a confirmaci&oacute;n.</span>
                </p>
                <div id="formButtons">
                    <input type="submit" id="sendMessage" name="sendMessage" value="Enviar" />
                    <input type="button" id="cancel" name="cancel" value="Cancelar" />
                </div>
            </div>
        </form>

        <div id="sendingMessage" class="statusMessage"><p>Enviando solicitud de cita. Por favor espere...</p></div>
        <div id="successMessage" class="statusMessage"><p>Gracias hemos recibido su solicitud de cita. Pronto le estaremos contactando.</p></div>
        <div id="failureMessage" class="statusMessage"><p>Ocurrio un problema enviando su mensaje. Por favor intentarlo de nuevo.</p></div>
        <div id="incompleteMessage" class="statusMessage"><p>Por favor ingrese los campos (requeridos).</p></div>
        <?php
        // put your code here
        ?>
    </body>
</html>


<script type="text/javascript">
    var messageDelay = 2000; // How long to display status messages (in milliseconds)
// Init the form once the document is ready
    $(init);
// Initialize the form
    function init() {

        $("#appointmentdate").datepicker({
            showOn: "button",
            buttonImage: "images/calendar-green.gif",
            dateFormat: 'dd/mm/yy',
            buttonImageOnly: true
        });
        $("#appointmentdate").mask("99/99/9999");
        $('#cancel').click(function() {
            parent.$.fancybox.close();
        });
    }
// Submit the form via Ajax
    function submitForm() {
        var contactForm = $(this);
// Are all the fields filled in?
        if (!$('#your-name').val() || !$('#your-email').val() || !$('#clinic').val() || !$('#appointmentdate').val() || !$('#appointmenttime').val() || !$('#cellphone').val()) {
// No; display a warning message and return to the form
            $('#incompleteMessage').fadeIn().delay(messageDelay).fadeOut();
            contactForm.fadeOut().delay(messageDelay).fadeIn();
        } else {
// Yes; submit the form to the PHP script via Ajax
            $('#sendingMessage').fadeIn();
            contactForm.fadeOut();
            $.ajax({
                url: contactForm.attr('action'),
                type: contactForm.attr('method'),
                data: contactForm.serialize(),
                success: submitFinished
            });
        }
// Prevent the default form submission occurring
        return false;
    }
// Handle the Ajax response
    function submitFinished(response) {
        response = $.trim(response);
        $('#sendingMessage').fadeOut();
        if (response == "success") {
// Form submitted successfully:
// 1. Display the success message
// 2. Clear the form fields
// 3. Fade the content back in
            $('#successMessage').fadeIn().delay(messageDelay).fadeOut();
            $('#your-name').val("");
            $('#your-email').val("");
            $('#cellphone').val("");
            $('#appointmentdate').val("");
            $('#your-message').val("");
            $('#container_main').delay(messageDelay + 500).fadeTo('slow', 1);
        } else {
// Form submission failed: Display the failure message,
// then redisplay the form
            $('#failureMessage').fadeIn().delay(messageDelay).fadeOut();
            $('#contactForm').delay(messageDelay + 500).fadeIn();
        }
    }
</script> 
<!--[if lt IE 7]>
<style type='text/css'>
        #simplemodal-container a.modalCloseImg {
                background:none;
                right:-14px;
                width:22px;
                height:26px;
                filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(
                        src='img/x.png', sizingMethod='scale'
                );
        }
</style>
 <![endif]-->
